//
//  pj_memory_allocate.h
//  pj-lib
//
//  Created by Pang Jun on 2/23/13.
//  Copyright (c) 2013 Pang Jun. All rights reserved.
//

#ifndef pj_lib_pj_memory_allocate_h
#define pj_lib_pj_memory_allocate_h

#include "pj_thuncks_alloc.h"
#include "pj_fragments_alloc.h"

#define THUNCK_SIZE 128

class MemoryAlloc
{
public:
    static void* allocate(long size)
    {
        if (size > THUNCK_SIZE)
        {
            return ChunksAlloc::allocate(size);
        }
        else
        {
            return FragmentsAlloc::allocate(size);
        }
    }
    static void deallocate(void *ptr, long size)
    {
        if (size > THUNCK_SIZE)
        {
            ChunksAlloc::deallocate(ptr, size);
        }
        else
        {
            FragmentsAlloc::deallocate(ptr, size);
        }
    }
	static void* realloc(void *ptr, long old_size, long new_size)
	{
		if (old_size > THUNCK_SIZE && new_size > THUNCK_SIZE)
		{
			return ChunksAlloc::reallocate(ptr, old_size, new_size);
		}
		else
		{
			return FragmentsAlloc::reallocate(ptr, old_size, new_size);
		}	
	}
};


#endif
